﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using T4.Models;

namespace T4.Controllers
{
    public class LoginController : Controller
    {
        private userEntities _context;
        public LoginController()
        {
            _context = new userEntities();
        }
        // GET: Login
        public ActionResult Index()
        {
            var courses = _context.users.ToList();
            return View(courses);
        }
        [HttpPost]
        public ActionResult Index(string username,string pwd)
        {
            var user = _context.users.FirstOrDefault(x => x.username == username);
            if (user == null)
            {
                ViewBag.Msg = "用户不存在";
            }
            else
            {
                //开始判断密码
                if (user.pwd == pwd)
                {
                    Session["user"] = user;
                    return RedirectToAction("Index", "Default");//跳转到主页
                }
                else
                {
                    
                    ViewBag.Msg = "用户名或密码错误！";
                }
            }
            return View();
        }

      
    }
}